<?xml version="1.0" encoding="utf-8" ?>
[#include "/WEB-INF/pages/common/taglibs.ftl"]
[#macro _script]
	<script type="text/javascript" src="[@c.url value='/js/plugins/jqwidgets/jqxcheckbox.js'/]"></script>
	<script type="text/javascript">
		var base = (function(){
			// 事件绑定
			function _addEventListeners() {
				//
				$('#siteFunctionForm').submit(function(){
    				var items = $('#jqxTree').jqxTree('getItems');
    				//var params = {};
    				var index = 0;
    				var _$form = $(this);
    				for(var i in items){
    					var item = items[i];
    					var _$item = $(item.element);
    					var id = _$item.attr('ckey');
    					var checked = item.checked;
    					if (checked == null) {
    						//checkbox=null(三值方框,有子节点被选中)
    						checked = true;
    					}
    					 _$form.append("<input type='hidden' name='siteFunctionList["+index+"].id' value="+id+" />");
    					 _$form.append("<input type='hidden' name='siteFunctionList["+index+"].enabled' value="+checked+" />");
    					//params['siteFunctionList['+index+'].id']=id;
    					//params['siteFunctionList['+index+'].enabled']=item.checked;
    					index++;
    				}
    				return true;
        		})
				// Create jqxExpander
        		$('.jqxExpander').jqxExpander({showArrow: false, toggleMode: 'none', height: '500px', theme: base.config.theme });
			}
			
			// 页面渲染
			function _treeRender () {
				// Create jqxTree
        		$('#jqxTree').jqxTree({height:'450px;', hasThreeStates: true, checkboxes: true, theme: base.config.theme });
        		$('#jqxTree').unbind().bind('select', function (event) {
	                var args = event.args.element.outerHTML;
	                var id = $('a', $(args)).attr('ckey');
					//使用一个ajax请求,去渲染body部分
					//参数注意：ajax代表是一个ajax请求;渲染本页的body,但在装饰器中为一个div体
					//所以在装饰器页里,将内容页放入不同位置,但内容页的ajax不会改变.
	                $.get(base.config.url, {'id':id, 'ajax':true, 'piece':true}, function(data){
	                	$('#siteFunctionView').html(data);
	                })
	            });
			};
			return {
                config: {
                	url : null,
                    theme: null
                },
                init: function () {
                	_addEventListeners();
                	_treeRender();
                }
			}
		}());
		
		$(function(){
			var link = "[@c.url value='/manage/SiteFunction_view.action'/]";
			base.config.theme = getTheme();
			base.config.url = link;
            //Initializing the form
			base.init();
		})
	</script>
[/#macro]
[#if piece==true]
	[@_script /]
	<!--设置提交行为-->
	[#assign act="save" /]
	<!--设置table渲染到指定ID节点-->
	[#assign renderTo="#functionList"]
	[#include "/WEB-INF/pages/manage/SiteFunction/_functionList.ftl"]
[#else]
	<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>Insert title here</title>
		<meta name="menu" content="AdminMenu"/>
		<meta name="heading" content="heading"/>
		<style type="text/css">
			.siteFunction {
				padding:0;
				margain:0;
			}
			.siteFunction_tree {
				width:240px;
				/*height:500px;*/
				float:left;
				margin-left:2px;
			}
			.siteFunction_view {
				/*height:500px;*/
				margin-left:246px;
				width:420px;
			}
		</style>
		[@_script /]
	</head>
	<body id="body" class="siteFunction_content">
		<div class="siteFunction">
			<div class="siteFunction_tree">
		    	[@s.action name="SiteFunction_tree" executeResult="true" namespace="/manage"]
		    		[@s.param name="ajax" value="true" /]
		    	[/@s.action]
		    </div>
			<div class="siteFunction_view">
				<div class="jqxExpander">
					<div>站点功能信息</div>
					<div id="siteFunctionView">
						功能展示
					</div>
				</div>
			</div>
			<div style="clear: both;"></div>
			<form id="siteFunctionForm" method="post" action="[@c.url value='/manage/SiteFunction_enable.action'][@c.param name="backurl" value="${currentUrl}"/][/@c.url]">
				<div><input type="submit" /></div>
			</form>
		</div>
	</body>
	</html>
[/#if]